package cs3343.project.family;

/**
 * The Class CharacterController.
 */
public class CharacterController {
	
	/** The gc. */
	private GameController gc;
	
	/** The players. */
	private Character[] players;
	
	/** The num of player. */
	private int numOfPlayer;
	
	/**
	 * Instantiates a new character controller.
	 *
	 * @param gc the gc
	 */
	public CharacterController(GameController gc) {
		this.gc = gc;
		players = new Character[ConfigManager.MAX_PLAYER];
	}
	
	/**
	 * Adds the player.
	 *
	 * @param player the player
	 * @param index the index
	 */
	public void addPlayer(Character player, int index) {
		players[index] = player;
	}
	
	/**
	 * Gets the player order.
	 *
	 * @param player the player
	 * @return the player order
	 */
	public int getPlayerOrder(Character player) {
		for (int i = 0; i < numOfPlayer; i++)
			if (players[i].equals(player))
				return i;
		return -1;
	}

	/**
	 * Gets the num of player.
	 *
	 * @return the num of player
	 */
	public int getNumOfPlayer() {
		return numOfPlayer;
	}

	/**
	 * Sets the num of player.
	 *
	 * @param numOfPlayer the new num of player
	 */
	public void setNumOfPlayer(int numOfPlayer) {
		this.numOfPlayer = numOfPlayer;
	}
	
	/**
	 * Gets the player.
	 *
	 * @param index the index
	 * @return the player
	 */
	public Character getPlayer(int index) {
		return players[index];
	}
	
	/**
	 * Gets the current player.
	 *
	 * @return the current player
	 */
	public Character getCurrentPlayer() {
		return players[gc.getCurrentPlayerIndex()];
	}
	
	/**
	 * Same player.
	 *
	 * @param a the a
	 * @param b the b
	 * @return true, if successful
	 */
	public boolean samePlayer(Character a, Character b) {
		if (a.getName().equalsIgnoreCase(b.getName()))
			return true;
		return false;		
	}
}
